package com.atguigu.linklist;

public class FindTheLastKListNode {
    public ListNode findTheKToTail(ListNode head,int k){
        if(head==null){
            return null;
        }
        int len=0;
        ListNode cur=head;
        while(cur!=null){
            cur=cur.next;
            len++;
        }
        if(k>len) return null;
        ListNode fast=head;
        ListNode slow=head;
        for(int i=0;i<k;i++){
            fast=fast.next;
        }
        while(fast!=null){
            fast=fast.next;
            slow=slow.next;
        }
        return slow;
    }
}
